package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.CreateMemberBean;
import com.shop2cn.iapi.member.parameter.MchSetMemberRemarkBean;
import com.shop2cn.iapi.member.service.MchSetMemberRemarkCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.sqlwapper.godmember.GodMemberWapper;
import com.ymttest.utils.TestDataManager;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
/**
*设置会员备注
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_MchSetMemberRemark{
	private static MchSetMemberRemarkBean mchsetmemberremarkBean;
	private static MchSetMemberRemarkCall mchsetmemberremarkCall;
	private static Integer shopid ;
	GodMemberWapper GodMemberWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置会员备注");
		try {
			shopid= GodmchManageCallService.CreateSellerMch();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {
		mchsetmemberremarkBean=new MchSetMemberRemarkBean();
		mchsetmemberremarkCall=new MchSetMemberRemarkCall();
		GodMemberWapper=new GodMemberWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(mchsetmemberremarkCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MchSetMemberRemark_001() {
		Logger.start(true,"设置会员备注成功");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			mchsetmemberremarkBean.setShopId(shopid);
			mchsetmemberremarkBean.setRemark("remark");
			mchsetmemberremarkBean.setMemberId(memid);
			mchsetmemberremarkCall.setData(mchsetmemberremarkBean);
			mchsetmemberremarkCall.callService();			
			Logger.verifyEquals("200", mchsetmemberremarkCall.getString("code"), "验证code");
			Logger.verifyEquals(mchsetmemberremarkBean.getRemark(),GodMemberWapper.selectMemberByMemberid(memid).get(0).getRemark(),"验证remark");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchSetMemberRemark_002() {
		Logger.start(true,"不输入shopid失败");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
//			mchsetmemberremarkBean.setShopId(shopid);
			mchsetmemberremarkBean.setRemark("remark");
			mchsetmemberremarkBean.setMemberId(memid);
			mchsetmemberremarkCall.setData(mchsetmemberremarkBean);
			mchsetmemberremarkCall.callService();			
			Logger.verifyEquals("400", mchsetmemberremarkCall.getString("code"), "验证code");
	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchSetMemberRemark_003() {
		Logger.start(true,"不输入memberid失败");
		try {
			//创建一个新会员
//			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
//			int userId = DGUserCallService.UserCreateCall(usercreateBean);
//			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
//			createMem.setOpenId(usercreateBean.getOpenId());
//			String memid = GodMemberService.creatememberCall(createMem);
			
			mchsetmemberremarkBean.setShopId(shopid);
			mchsetmemberremarkBean.setRemark("remark");
//			mchsetmemberremarkBean.setMemberId(memid);
			mchsetmemberremarkCall.setData(mchsetmemberremarkBean);
			mchsetmemberremarkCall.callService();			
			Logger.verifyEquals("400", mchsetmemberremarkCall.getString("code"), "验证code");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchSetMemberRemark_004() {
		Logger.start(true,"shopid和memberid不匹配失败");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			mchsetmemberremarkBean.setShopId(shopid+1);
			mchsetmemberremarkBean.setRemark("remark");
			mchsetmemberremarkBean.setMemberId(memid);
			mchsetmemberremarkCall.setData(mchsetmemberremarkBean);
			mchsetmemberremarkCall.callService();			
			Logger.verifyEquals("200", mchsetmemberremarkCall.getString("code"), "验证code");
			Logger.verifyEquals("false", mchsetmemberremarkCall.getString("data"), "验证data");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchSetMemberRemark_005() {
		Logger.start(true,"不输入remark失败");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			mchsetmemberremarkBean.setShopId(shopid);
//			mchsetmemberremarkBean.setRemark("remark");
			mchsetmemberremarkBean.setMemberId(memid);
			mchsetmemberremarkCall.setData(mchsetmemberremarkBean);
			mchsetmemberremarkCall.callService();			
			Logger.verifyEquals("400", mchsetmemberremarkCall.getString("code"), "验证code");
			Logger.verifyEquals(mchsetmemberremarkBean.getRemark(),GodMemberWapper.selectMemberByMemberid(memid).get(0).getRemark(),"验证remark");
	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_MchSetMemberRemark_006() {
		Logger.start(true,"输入remark空字符串成功");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			mchsetmemberremarkBean.setShopId(shopid);
			mchsetmemberremarkBean.setRemark("");
			mchsetmemberremarkBean.setMemberId(memid);
			mchsetmemberremarkCall.setData(mchsetmemberremarkBean);
			mchsetmemberremarkCall.callService();			
			Logger.verifyEquals("200", mchsetmemberremarkCall.getString("code"), "验证code");
			Logger.verifyEquals(mchsetmemberremarkBean.getRemark(),GodMemberWapper.selectMemberByMemberid(memid).get(0).getRemark(),"验证remark");

			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_MchSetMemberRemark_007() {
		Logger.start(true,"设置会员备注超长失败");
		try {
			//创建一个新会员
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			CreateMemberBean createMem = GodMemberService.initCreateMemberBean(shopid,userId,usercreateBean.getOpenId());
			createMem.setOpenId(usercreateBean.getOpenId());
			String memid = GodMemberService.creatememberCall(createMem);
			
			mchsetmemberremarkBean.setShopId(shopid);
			String remark=TestDataManager.getRandomNum(200);
			mchsetmemberremarkBean.setRemark(remark);
			mchsetmemberremarkBean.setMemberId(memid);
			mchsetmemberremarkCall.setData(mchsetmemberremarkBean);
			mchsetmemberremarkCall.callService();			
			Logger.verifyEquals("200", mchsetmemberremarkCall.getString("code"), "验证code");
			Logger.verifyEquals(mchsetmemberremarkBean.getRemark(),GodMemberWapper.selectMemberByMemberid(memid).get(0).getRemark(),"验证remark");
			remark=TestDataManager.getRandomNum(2010);
			mchsetmemberremarkBean.setRemark(remark);
			mchsetmemberremarkCall.callService();			
			Logger.verifyEquals("400", mchsetmemberremarkCall.getString("code"), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}